{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Unique Morse Code Words"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #hash-table #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #哈希表 #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: uniqueMorseRepresentations"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #唯一摩尔斯密码词"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>国际摩尔斯密码定义一种标准编码方式，将每个字母对应于一个由一系列点和短线组成的字符串，&nbsp;比如:</p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>'a'</code> 对应 <code>\".-\"</code> ，</li>\n",
    "\t<li><code>'b'</code> 对应 <code>\"-...\"</code> ，</li>\n",
    "\t<li><code>'c'</code> 对应 <code>\"-.-.\"</code> ，以此类推。</li>\n",
    "</ul>\n",
    "\n",
    "<p>为了方便，所有 <code>26</code> 个英文字母的摩尔斯密码表如下：</p>\n",
    "\n",
    "<pre>\n",
    "[\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]</pre>\n",
    "\n",
    "<p>给你一个字符串数组 <code>words</code> ，每个单词可以写成每个字母对应摩尔斯密码的组合。</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>例如，<code>\"cab\"</code> 可以写成 <code>\"-.-..--...\"</code> ，(即 <code>\"-.-.\"</code> + <code>\".-\"</code> + <code>\"-...\"</code> 字符串的结合)。我们将这样一个连接过程称作 <strong>单词翻译</strong> 。</li>\n",
    "</ul>\n",
    "\n",
    "<p>对<strong> </strong><code>words</code> 中所有单词进行单词翻译，返回不同 <strong>单词翻译</strong> 的数量。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入:</strong> words = [\"gin\", \"zen\", \"gig\", \"msg\"]\n",
    "<strong>输出:</strong> 2\n",
    "<strong>解释: </strong>\n",
    "各单词翻译如下:\n",
    "\"gin\" -&gt; \"--...-.\"\n",
    "\"zen\" -&gt; \"--...-.\"\n",
    "\"gig\" -&gt; \"--...--.\"\n",
    "\"msg\" -&gt; \"--...--.\"\n",
    "\n",
    "共有 2 种不同翻译, \"--...-.\" 和 \"--...--.\".\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>words = [\"a\"]\n",
    "<strong>输出：</strong>1\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= words.length &lt;= 100</code></li>\n",
    "\t<li><code>1 &lt;= words[i].length &lt;= 12</code></li>\n",
    "\t<li><code>words[i]</code> 由小写英文字母组成</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [unique-morse-code-words](https://leetcode.cn/problems/unique-morse-code-words/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [unique-morse-code-words](https://leetcode.cn/problems/unique-morse-code-words/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[\"gin\",\"zen\",\"gig\",\"msg\"]', '[\"a\"]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        rec = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        res = []\n",
    "        for word in words:\n",
    "            tmp = ''\n",
    "            for i in word:\n",
    "                tmp += rec[ord(i) - ord('a')]\n",
    "            if tmp not in res:\n",
    "                res.append(tmp)\n",
    "        return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        morsecode = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        return len(set(\"\".join(morsecode[ord(ch)-ord('a')] for ch in word) for word in words))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "MORSE = [\".-\", \"-...\", \"-.-.\", \"-..\", \".\", \"..-.\", \"--.\",\n",
    "         \"....\", \"..\", \".---\", \"-.-\", \".-..\", \"--\", \"-.\",\n",
    "         \"---\", \".--.\", \"--.-\", \".-.\", \"...\", \"-\", \"..-\",\n",
    "         \"...-\", \".--\", \"-..-\", \"-.--\", \"--..\"]\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        return len(set(\"\".join(MORSE[ord(ch) - ord('a')] for ch in word) for word in words))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "MORSE = [\".-\", \"-...\", \"-.-.\", \"-..\", \".\", \"..-.\", \"--.\",\n",
    "         \"....\", \"..\", \".---\", \"-.-\", \".-..\", \"--\", \"-.\",\n",
    "         \"---\", \".--.\", \"--.-\", \".-.\", \"...\", \"-\", \"..-\",\n",
    "         \"...-\", \".--\", \"-..-\", \"-.--\", \"--..\"]\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        return len(set(\"\".join(MORSE[ord(ch) - ord('a')] for ch in word) for word in words))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        codelist=[\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        codeset={0}\n",
    "        for i in words:\n",
    "            temp=''\n",
    "            for j in i:\n",
    "                temp+=codelist[int(ord(j)-ord('a'))]\n",
    "            codeset.add(temp)\n",
    "        return len(codeset)-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        moe = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        res = []\n",
    "        for i in words:\n",
    "            i_str = \"\"\n",
    "            for j in i:\n",
    "                i_str += moe[ord(j) - ord('a')]\n",
    "            res.append(i_str)\n",
    "        return len(set(res))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        MORSE = [\".-\", \"-...\", \"-.-.\", \"-..\", \".\", \"..-.\", \"--.\",\n",
    "         \"....\", \"..\", \".---\", \"-.-\", \".-..\", \"--\", \"-.\",\n",
    "         \"---\", \".--.\", \"--.-\", \".-.\", \"...\", \"-\", \"..-\",\n",
    "         \"...-\", \".--\", \"-..-\", \"-.--\", \"--..\"]\n",
    "        return len(set(\"\".join(MORSE[ord(ch) - ord('a')] for ch in word) for word in words))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        hasp_map = {'a': '.-', 'b': '-...', 'c': '-.-.', 'd': '-..', 'e': '.', 'f': '..-.', 'g': '--.', 'h': '....',\n",
    "                    'i': '..', 'j': '.---', 'k': '-.-', 'l': '.-..', 'm': '--', 'n': '-.', 'o': '---', 'p': '.--.',\n",
    "                    'q': '--.-', 'r': '.-.', 's': '...', 't': '-', 'u': '..-', 'v': '...-', 'w': '.--', 'x': '-..-',\n",
    "                    'y': '-.--', 'z': '--..'}\n",
    "        res = set()\n",
    "        for i in words:\n",
    "            s = ''\n",
    "            for j in range(len(i)):\n",
    "                s += hasp_map[i[j]]\n",
    "            res.add(s)\n",
    "        return len(res)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "CODE = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        return len(set(\"\".join(CODE[ord(c) - ord('a')] for c in word) for word in words))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        d = {'a': '.-', 'b': '-...', 'c': '-.-.', 'd': '-..', 'e': '.', 'f': '..-.', 'g': '--.', 'h': '....', 'i': '..', 'j': '.---', 'k': '-.-', 'l': '.-..', 'm': '--', 'n': '-.', 'o': '---', 'p': '.--.', 'q': '--.-', 'r': '.-.', 's': '...', 't': '-', 'u': '..-', 'v': '...-', 'w': '.--', 'x': '-..-', 'y': '-.--', 'z': '--..'}\n",
    "        res = set()\n",
    "        for word in words:\n",
    "            chars = ''\n",
    "            for char in word:\n",
    "                chars += d[char]\n",
    "            res.add(chars)\n",
    "        return len(res)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "MORSE = [\".-\", \"-...\", \"-.-.\", \"-..\", \".\", \"..-.\", \"--.\",\n",
    "         \"....\", \"..\", \".---\", \"-.-\", \".-..\", \"--\", \"-.\",\n",
    "         \"---\", \".--.\", \"--.-\", \".-.\", \"...\", \"-\", \"..-\",\n",
    "         \"...-\", \".--\", \"-..-\", \"-.--\", \"--..\"]\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        return len(set(\"\".join(MORSE[ord(ch) - ord('a')] for ch in word) for word in words))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        code = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        mourse = [ ''.join(code[ord(c) - ord('a')] for c in word) for word in words]\n",
    "        return len(set(mourse))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        dictionary = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        res = set()\n",
    "        for word in words:\n",
    "            t = ''\n",
    "            for c in word:\n",
    "                t+=dictionary[ord(c)-ord('a')]\n",
    "            res.add(t)\n",
    "        return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        word_change = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        if len(words) == 1:\n",
    "            return 1\n",
    "        result_list = []\n",
    "        for word in words:\n",
    "            temp_c = ''\n",
    "            for w in word:\n",
    "                ind = ord(w) - ord('a')\n",
    "                temp_c += word_change[ind]\n",
    "            if temp_c not in result_list:\n",
    "                result_list.append(temp_c)\n",
    "        return len(result_list)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        morse = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        ans = []\n",
    "        for word in words:\n",
    "            tmp = ''\n",
    "            for ch in word:\n",
    "                ind = ord(ch) - 97\n",
    "                tmp += morse[ind]\n",
    "            if tmp not in ans:\n",
    "                ans.append(tmp)\n",
    "        return len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        codelist=[\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        return len(set(\"\".join(codelist[ord(ch) - ord('a')] for ch in word) for word in words))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        letters = [\".-\", \"-...\", \"-.-.\", \"-..\", \".\", \"..-.\", \"--.\", \"....\", \"..\", \".---\",\n",
    "               \"-.-\", \".-..\", \"--\", \"-.\", \"---\", \".--.\", \"--.-\", \".-.\", \"...\", \"-\", \"..-\",\n",
    "               \"...-\", \".--\", \"-..-\", \"-.--\", \"--..\"]\n",
    "        seen = set()\n",
    "        for word in words:\n",
    "            res = ''\n",
    "            for ch in word:\n",
    "                res += letters[ord(ch) - ord('a')]\n",
    "            seen.add(res)\n",
    "        return len(seen)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "MORSE = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        return len(set(\"\".join(MORSE[ord(ch) - ord('a')] for ch in word) for word in words))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        mos = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        lowers = 'abcdefghijklmnopqrstuvwxyz'\n",
    "        dic = {}\n",
    "        for i , k in zip(lowers,mos):\n",
    "            dic[i] = k\n",
    "        result = []\n",
    "        for m in words:\n",
    "            tem = ''\n",
    "            for n in m:\n",
    "                tem += dic[n]\n",
    "            result.append(tem)\n",
    "        return len(set(result))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        hash_map = {}\n",
    "        alpha = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        for word in words:\n",
    "            res = \"\"\n",
    "            for i in word:\n",
    "                res += alpha[ord(i) - ord(\"a\")]\n",
    "            if res in hash_map:\n",
    "                hash_map[res] += 1\n",
    "            else:\n",
    "                hash_map[res] = 1\n",
    "        return len(hash_map)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "m = [\".-\", \"-...\", \"-.-.\", \"-..\", \".\", \"..-.\", \"--.\",\n",
    "         \"....\", \"..\", \".---\", \"-.-\", \".-..\", \"--\", \"-.\",\n",
    "         \"---\", \".--.\", \"--.-\", \".-.\", \"...\", \"-\", \"..-\",\n",
    "         \"...-\", \".--\", \"-..-\", \"-.--\", \"--..\"]\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        #s = \"\".join(m[ord(ch) - ord('a')] for ch in word) for word in words\n",
    "        return len(set(\"\".join(m[ord(ch) - ord('a')] for ch in word) for word in words))\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        table = [\n",
    "            \".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\n",
    "            \"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\n",
    "            \"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"\n",
    "        ]\n",
    "\n",
    "        ans = set()\n",
    "        for word in words:\n",
    "            tmp = \"\"\n",
    "            for ch in word:\n",
    "                tmp += table[ord(ch)-97]\n",
    "            ans.add(tmp)\n",
    "        \n",
    "        return len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        mossList = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        res = set()\n",
    "        for w in words:\n",
    "            moss = ''\n",
    "            for c in w:\n",
    "                moss += mossList[ord(c) - ord('a')]\n",
    "            if moss not in res:\n",
    "                res.add(moss)\n",
    "        return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        mossList = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        res = []\n",
    "        for w in words:\n",
    "            moss = ''\n",
    "            for c in w:\n",
    "                moss += mossList[ord(c) - ord('a')]\n",
    "            res.append(moss)\n",
    "        return len(set(res))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        morse = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        res = set()\n",
    "        for word in words:\n",
    "            cur = ''\n",
    "            for c in word:\n",
    "                cur += morse[ord(c) - ord('a')]\n",
    "            res.add(cur)\n",
    "        return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        code = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        count = set()\n",
    "        res = 0\n",
    "        for word in words:\n",
    "            temp = [code[ord(i)-ord(\"a\")] for i in word]\n",
    "            if \"\".join(temp) not in count:\n",
    "                count.add(\"\".join(temp))\n",
    "                res += 1\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        moersi = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        alp = [chr(i) for i in range(97,123)]\n",
    "        hash_T = {alp[i]:moersi[i] for i in range(len(moersi))}\n",
    "        ans = []\n",
    "        for word in words:\n",
    "            s = ''\n",
    "            for ch in word:\n",
    "                s += hash_T[ch]\n",
    "            ans.append(s)\n",
    "        return len(set(ans))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        std =[\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        classes = []\n",
    "      \n",
    "        for word in words:\n",
    "            string =''\n",
    "            for i in range(len(word)):\n",
    "                string += std[ord(word[i])-97]\n",
    "            if string not in classes:\n",
    "                classes.append(string)\n",
    "        return len(classes)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        idx = []\n",
    "        secret  =[\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        for i in words:\n",
    "            s=[]\n",
    "            for j in i:\n",
    "                s.append(secret[ord(j)-ord('a')])\n",
    "            idx.append(\"\".join(s))\n",
    "        return (len(set(idx)))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        morsecode = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        rep = []\n",
    "        for word in words:\n",
    "            code = \"\"\n",
    "            for ch in word:\n",
    "                code += morsecode[ord(ch.lower())-97]\n",
    "            rep.append(code)\n",
    "        return len(set(rep))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        wordlist = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        res = []\n",
    "        for word in words:\n",
    "            temp = ''\n",
    "            for num in word:\n",
    "                 temp += wordlist[ord(num) - ord('a')]\n",
    "            res.append(temp)\n",
    "        return len(set(res))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        mors_list = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        zimu_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\n",
    "        words_list = []\n",
    "        for word in words:\n",
    "            flag = ''\n",
    "            for w in word:\n",
    "                flag += mors_list[zimu_list.index(w)]\n",
    "            words_list.append(flag)\n",
    "        return len(list(set(words_list)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        mima = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        # print(ord(\"a\"))\n",
    "        l=[]\n",
    "        for word in words:\n",
    "            ask = \"\"\n",
    "            for letter in word:\n",
    "                ask = ask + mima[ord(letter)-97]\n",
    "            l.append(ask)\n",
    "        return len(set(l))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        morse=[\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        chars=list('abcdefghijklmnopqrstuvwxyz')\n",
    "        morse_dict=dict(zip(chars,morse))\n",
    "        \n",
    "        diff_results=set()\n",
    "        for word in words:\n",
    "            diff_results.add(''.join([morse_dict[c] for c in word]))\n",
    "\n",
    "        return len(diff_results)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        mm = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        re = []\n",
    "        for word in words:\n",
    "            tmp = \"\"\n",
    "            for s in word:\n",
    "                tmp = tmp + mm[ord(s)-ord('a')]\n",
    "            if tmp not in re:\n",
    "                re.append(tmp)\n",
    "        return len(re)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        mosi=[\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "\n",
    "        return len(set(''.join(mosi[ord(ch) - ord('a')] for ch in word) for word in words))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "MORSE = [\".-\", \"-...\", \"-.-.\", \"-..\", \".\", \"..-.\", \"--.\",\n",
    "         \"....\", \"..\", \".---\", \"-.-\", \".-..\", \"--\", \"-.\",\n",
    "         \"---\", \".--.\", \"--.-\", \".-.\", \"...\", \"-\", \"..-\",\n",
    "         \"...-\", \".--\", \"-..-\", \"-.--\", \"--..\"]\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        return len(set(\"\".join(MORSE[ord(ch) - ord('a')] for ch in word) for word in words))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        dic = dict(zip([chr(x) for x in range(97, 124)], [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]))\n",
    "        s = set()\n",
    "        for x in words:\n",
    "            s.add(\"\".join(dic[y] for y in x))\n",
    "        return len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        mosi=[\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "\n",
    "        return len(set(''.join(mosi[ord(ch) - ord('a')] for ch in word) for word in words))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        secret  =[\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        s = [''.join(secret[ord(j)-ord('a')] for j in word)for word in words]\n",
    "        return (len(set(s)))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "\n",
    "        fanyi=[\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        result=[]\n",
    "        for a in words:\n",
    "            temp=\"\"\n",
    "            for b in a:\n",
    "                temp +=fanyi[ord(b)-97]\n",
    "            result.append(temp)\n",
    "        \n",
    "        print(result)\n",
    "        return len(set(result))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "MORSECODE = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "TABLE = dict(zip(ascii_lowercase, MORSECODE))\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        return len(set(''.join(TABLE[c] for c in w) for w in words))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "MORSE = [\".-\", \"-...\", \"-.-.\", \"-..\", \".\", \"..-.\", \"--.\",\n",
    "         \"....\", \"..\", \".---\", \"-.-\", \".-..\", \"--\", \"-.\",\n",
    "         \"---\", \".--.\", \"--.-\", \".-.\", \"...\", \"-\", \"..-\",\n",
    "         \"...-\", \".--\", \"-..-\", \"-.--\", \"--..\"]\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        return len(set(\"\".join(MORSE[ord(ch) - ord('a')] for ch in word) for word in words))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        # 翻译完一个放入set\n",
    "        s = set()\n",
    "        table = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        for word in words:\n",
    "            cur = \"\"\n",
    "            for ch in word :\n",
    "                cur += table[ord(ch)-ord('a')]\n",
    "            s.add(cur)\n",
    "        return len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    lMors = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "    lz = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\n",
    "    dZ2MMap = {z : m for z, m in zip(lz, lMors)}\n",
    "    def uniqueMorseRepresentations(self, words) -> int:\n",
    "        rst = set()\n",
    "        for word in words:\n",
    "            s = ''.join(\n",
    "                [self.dZ2MMap[c] for c in word]\n",
    "            )\n",
    "            rst.add(s)\n",
    "        return len(rst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        dict_char = [\".-\", \"-...\", \"-.-.\", \"-..\", \".\", \"..-.\", \"--.\", \"....\", \"..\", \".---\", \"-.-\", \".-..\", \"--\", \"-.\",\n",
    "                     \"---\", \".--.\", \"--.-\", \".-.\", \"...\", \"-\", \"..-\", \"...-\", \".--\", \"-..-\", \"-.--\", \"--..\"]\n",
    "        dict_char = {chr(i + 97): password for i, password in enumerate(dict_char)}\n",
    "        result = set()\n",
    "        for word in words:\n",
    "            password = \"\"\n",
    "            for char in word:\n",
    "                password += dict_char[char]\n",
    "            result.add(password)\n",
    "        return len(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "MORSE = [\".-\", \"-...\", \"-.-.\", \"-..\", \".\", \"..-.\", \"--.\",\n",
    "         \"....\", \"..\", \".---\", \"-.-\", \".-..\", \"--\", \"-.\",\n",
    "         \"---\", \".--.\", \"--.-\", \".-.\", \"...\", \"-\", \"..-\",\n",
    "         \"...-\", \".--\", \"-..-\", \"-.--\", \"--..\"]\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        return len(set(\"\".join(MORSE[ord(ch) - ord('a')] for ch in word) for word in words))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        li = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        s = []\n",
    "        for word in words:\n",
    "            now = \"\"\n",
    "            for e in word:\n",
    "                now = now + li[self.getNum(e)]\n",
    "            if now not in s:\n",
    "                s.append(now)\n",
    "        return len(s)\n",
    "    def getNum(self,alpha:str) -> int:\n",
    "        return ord(alpha) - 97"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        morse = [\".-\", \"-...\", \"-.-.\", \"-..\", \".\", \"..-.\", \"--.\", \"....\", \"..\", \".---\", \"-.-\", \".-..\", \"--\", \"-.\",\n",
    "                 \"---\", \".--.\", \"--.-\", \".-.\", \"...\", \"-\", \"..-\", \"...-\", \".--\", \"-..-\", \"-.--\", \"--..\"]\n",
    "        different_morse = set()\n",
    "        for ele in words:\n",
    "            s = ''\n",
    "            for i in ele:\n",
    "                s += \"\".join(morse[ord(i) - ord('a')])\n",
    "            different_morse.add(s)\n",
    "        return len(different_morse)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        lst = [\".-\", \"-...\", \"-.-.\", \"-..\", \".\", \"..-.\", \"--.\", \"....\", \"..\", \".---\", \"-.-\", \".-..\", \"--\", \"-.\", \"---\",\".--.\", \"--.-\", \".-.\", \"...\", \"-\", \"..-\", \"...-\", \".--\", \"-..-\", \"-.--\", \"--..\"]\n",
    "        morse = {\"0\"}\n",
    "        word = \"\"\n",
    "        for i in range(len(words)):\n",
    "            for j in range(len(words[i])):\n",
    "                word += lst[ord(words[i][j]) - 97]\n",
    "            morse.add(word)\n",
    "            word = \"\"\n",
    "        return len(morse) - 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        \"\"\"唯一摩尔斯密码词----暴力破解\"\"\"\n",
    "        dic = {'a': '.-', 'b': '-...', 'c': '-.-.', 'd': '-..', 'e': '.', 'f': '..-.', 'g': '--.', 'h': '....','i': '..', 'j': '.---', 'k': '-.-', 'l': '.-..', 'm': '--', 'n': '-.', 'o': '---', 'p': '.--.','q': '--.-', 'r': '.-.', 's': '...', 't': '-', 'u': '..-', 'v': '...-', 'w': '.--', 'x': '-..-','y': '-.--', 'z': '--..'}\n",
    "        lst = []\n",
    "        for i in words:\n",
    "            s = ''\n",
    "            for j in i:\n",
    "                s += dic[j]\n",
    "            lst.append(s)\n",
    "        return len(set(lst))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        str_,list_='',[]\n",
    "        ms=[\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        for i in words:\n",
    "            for j in i:\n",
    "                str_+=ms[ord(j)-97]\n",
    "            if str_ not in list_:\n",
    "                list_.append(str_)\n",
    "            str_=''\n",
    "        return len(list_)\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        s1=[\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        code=[]\n",
    "        for word in words:\n",
    "            codeletter=''\n",
    "            for i in word:\n",
    "                #print(i,s1[ord(i)-97])\n",
    "                codeletter+=s1[ord(i)-97]\n",
    "            #print(word,codeletter)\n",
    "            code.append(codeletter)\n",
    "        return len(set(code))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        lst = [\".-\", \"-...\", \"-.-.\", \"-..\", \".\", \"..-.\", \"--.\", \"....\", \"..\", \".---\", \"-.-\", \".-..\", \"--\", \"-.\", \"---\",\n",
    "        \".--.\", \"--.-\", \".-.\", \"...\", \"-\", \"..-\", \"...-\", \".--\", \"-..-\", \"-.--\", \"--..\"]\n",
    "        morse = {\"0\"}\n",
    "        word = \"\"\n",
    "        for i in range(len(words)):\n",
    "            for j in range(len(words[i])):\n",
    "                word += lst[ord(words[i][j]) - 97]\n",
    "            morse.add(word)\n",
    "            word = \"\"\n",
    "        return len(morse) - 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        code=[\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        res=list()\n",
    "        alpha=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\n",
    "        for i in words:\n",
    "            coded=''\n",
    "            for m in i:\n",
    "                n=alpha.index(m)\n",
    "                \n",
    "                coded+=code[n]\n",
    "            if coded not in res:\n",
    "                res.append(coded)\n",
    "        return len(res) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        \n",
    "        if len(words) == 1:\n",
    "            return 1\n",
    "\n",
    "        result = set()\n",
    "        base = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "\n",
    "        for i in words:\n",
    "            temp_string = \"\"\n",
    "            for j in i:\n",
    "                index = ord(j) - 97\n",
    "                temp_string += base[index]\n",
    "            \n",
    "            #if temp_string not in result:\n",
    "                #.append(temp_string)\n",
    "            result.add(temp_string)\n",
    "        \n",
    "        return len(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        lst=\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"\n",
    "        dic={chr(i+97):x for i,x in enumerate(lst)}\n",
    "        ans=[]\n",
    "        for word in words:\n",
    "            string=\"\"\n",
    "            for i in word:\n",
    "                string+=dic[i]\n",
    "            if string not in ans:\n",
    "                ans.append(string)\n",
    "        return len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        temp = ['']*len(words)\n",
    "        pasdword = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        for i,v in enumerate(words):\n",
    "            for j in v:\n",
    "                temp[i]+=pasdword[ord(j)-97]\n",
    "        return len(list(set(temp)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        code=[\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        res=set()\n",
    "        for word in words:\n",
    "            ans=\"\"\n",
    "            for ch in word:\n",
    "                idx=ord(ch)-ord('a')\n",
    "                ans+=code[idx]\n",
    "            res.add(ans)\n",
    "        # print(res)\n",
    "        # print(len(res))\n",
    "        return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        moss = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        st = set()\n",
    "        for word in words:\n",
    "            ms = \"\"\n",
    "            for w in word:\n",
    "                ms += moss[ord(w) - 97]   # ord(a) = 97\n",
    "            st.add(ms)\n",
    "        return len(st)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        password_dict = {alpha: value for alpha, value in zip(\"abcdefghijklmnopqrstuvwxyz\",[\".-\", \"-...\", \"-.-.\", \"-..\", \".\", \"..-.\", \"--.\", \"....\",\"..\", \".---\", \"-.-\", \".-..\", \"--\", \"-.\", \"---\",\".--.\", \"--.-\", \".-.\", \"...\", \"-\", \"..-\", \"...-\", \".--\",\"-..-\", \"-.--\", \"--..\"])}\n",
    "        t=set()\n",
    "        for i in words:\n",
    "            s=''\n",
    "            for j in i:\n",
    "                s+=password_dict[j]\n",
    "            t.add(s)\n",
    "        return len(t)\n",
    "\n",
    "\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        morse = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        # return ord('a')\n",
    "        s = set()\n",
    "        for i in words:\n",
    "            tmp = ''\n",
    "            for j in i:\n",
    "                tmp = tmp + (morse[ord(j)-97])\n",
    "            s.add(tmp)\n",
    "        return len(s)\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    lMors = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\r\n",
    "    lz = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\r\n",
    "    dZ2MMap = {z : m for z, m in zip(lz, lMors)}\r\n",
    "    def uniqueMorseRepresentations(self, words) -> int:\r\n",
    "        rst = set()\r\n",
    "        for word in words:\r\n",
    "            s = ''.join(\r\n",
    "                (self.dZ2MMap[c] for c in word)\r\n",
    "            )\r\n",
    "            rst.add(s)\r\n",
    "        return len(rst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        alphalst = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\n",
    "        \".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"\n",
    "        ]\n",
    "        res = set()\n",
    "        for i in words:\n",
    "            temp_str = ''\n",
    "            for j in i:\n",
    "                temp = ord(j) - 97\n",
    "                temp_str = temp_str + alphalst[temp]\n",
    "            res.add(temp_str)\n",
    "        return len(res) \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "map = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "def getMols(str1):\n",
    "    result = \"\"\n",
    "    for s in str1:\n",
    "        index = ord(s)-97\n",
    "        result += map[index]\n",
    "    return result\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        set1 = set()\n",
    "        for w in words:\n",
    "            val = getMols(w)\n",
    "            set1.add(val)\n",
    "        return len(set1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        syl = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        morse = []\n",
    "        for i in words:\n",
    "            temp = \"\"\n",
    "            for j in i:\n",
    "                temp += syl[ord(j)-97]\n",
    "            morse.append(temp)\n",
    "        ans = []\n",
    "        for i in morse:\n",
    "            if i not in ans:\n",
    "                ans.append(i)\n",
    "\n",
    "        return(len(ans))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:    \n",
    "    def uniqueMorseRepresentations(self, words: list[str]) -> int: \n",
    "        codeMap = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\n",
    "                   \"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\n",
    "                   \"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\n",
    "                   \"-.--\",\"--..\"]\n",
    "        decode = []\n",
    "        sec = ''\n",
    "        for word in words:\n",
    "            for letter in word:\n",
    "                sec = sec + codeMap[ord(letter) - 97]\n",
    "            decode.append(sec)\n",
    "            sec = ''\n",
    "        # print(str(decode))\n",
    "        dataSet = set(decode)\n",
    "        res_dic = {}\n",
    "        for i in dataSet:\n",
    "            res_dic.update({i: decode.count(i)})\n",
    "        return len(res_dic)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "      letters=[\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "      match= set()\n",
    "      for word in words:\n",
    "        tmp = \"\"\n",
    "        for char in word:\n",
    "          tmp += letters[ord(char)-ord(\"a\")]\n",
    "        match.add(tmp)\n",
    "      return len(match)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "MORSECODE = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "TABLE = dict(zip(ascii_lowercase, MORSECODE))\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        set_ = set()\n",
    "        for w in words:\n",
    "            s = ''.join(TABLE[c] for c in w)\n",
    "            set_.add(s)\n",
    "        return len(set_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "map = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "def getMols(str1):\n",
    "    result = \"\"\n",
    "    for s in str1:\n",
    "        index = ord(s)-97\n",
    "        result += map[index]\n",
    "    return result\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        set1 = set()\n",
    "        for w in words:\n",
    "            val = getMols(w)\n",
    "            print(w,val)\n",
    "            set1.add(val)\n",
    "        return len(set1)\n",
    "\n",
    "        print(ord(\"a\"))\n",
    "        print(ord(\"b\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words) -> int:\n",
    "        lMors = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        lz = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\n",
    "        dZ2MMap = {z : m for z, m in zip(lz, lMors)}\n",
    "        rst = set()\n",
    "        for word in words:\n",
    "            s = ''.join(\n",
    "                [dZ2MMap[c] for c in word]\n",
    "            )\n",
    "            # return dZ2MMap\n",
    "            # return [dZ2MMap[c] for c in word]\n",
    "            rst.add(s)\n",
    "\n",
    "        return len(rst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "CODE = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        return len(set(\"\".join(CODE[ord(c) - ord('a')] for c in word) for word in words))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        CODE = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        return len(set(\"\".join(CODE[ord(c) - ord('a')] for c in word) for word in words))\n",
    "\n",
    "# 作者：Benhao\n",
    "# 链接：https://leetcode.cn/problems/unique-morse-code-words/solutions/1408137/pythonjavajavascriptgo-bao-li-by-himymbe-m0vo/\n",
    "# 来源：力扣（LeetCode）\n",
    "# 著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def uniqueMorseRepresentations(self, words: List[str]) -> int:\n",
    "        ss = [\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\n",
    "        ans = set()\n",
    "        for ch in words:\n",
    "            string = \"\"\n",
    "            for c in ch:\n",
    "                string += ss[ord(c) - ord(\"a\")]\n",
    "            ans.add(string)\n",
    "        return len(ans)\n",
    "        "
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
